package _5YuanXin;

import _5YuanXin.sub.Circle;
import _5YuanXin.sub.Rectangle;
import _5YuanXin.sub.Square;

import java.util.Hashtable;

/**
 * @ShapeCache: 图形缓存类
 * @author: ZBoHang
 * @time: 2021/9/7 13:19
 */
public class ShapeCache {

    private static Hashtable<String, Shape> shapeMap = new Hashtable<>();

    public static Shape getShape(String shapeId) throws CloneNotSupportedException {
        return ((Shape) shapeMap.get(shapeId).clone());
    }

    public static void  loadCache() throws CloneNotSupportedException {
        Circle circle = new Circle();
        circle.setId("1");
        shapeMap.put(circle.getId(), circle);

        Square square = new Square();
        square.setId("2");
        shapeMap.put(square.getId(), square);

        Rectangle rectangle = new Rectangle();
        rectangle.setId("3");
        shapeMap.put(rectangle.getId(), rectangle);
    }
}
